<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin:0;
            padding:0;
        }
    </style>
</head>
<body>
    <canvas id="canvas" width="375" height="667"></canvas>

    <script>
        // // 1. 获取canvas元素
        // let canvas = document.querySelector("#canvas");

        // //2. 获取画笔对象
        // let ctx = canvas.getContext('2d');

        // //3. 移动画笔
        // ctx.moveTo(100, 100);

        // //4. 绘制图形 绘线
        // ctx.lineTo(200, 100);

        // ctx.strokeStyle = 'rgb(20,50,200)';
        // ctx.lineWidth = 20;
        // //5. 描边
        // ctx.stroke();

        document.addEventListener('touchstart', function(e){
            e.preventDefault()
        }, {
            passive: false    
        })

        //绑定事件
        let canvas = document.querySelector("#canvas");
        //设置画布的宽度和高度
        canvas.width = document.documentElement.clientWidth;
        canvas.height = document.documentElement.clientHeight;

        let ctx = canvas.getContext('2d');

        //绑定事件
        canvas.addEventListener('touchstart', function(e){
            let x = e.changedTouches[0].clientX;
            let y = e.changedTouches[0].clientY;
            //移动画笔
            ctx.moveTo(x, y);
        });

        canvas.addEventListener('touchmove', function(e){
            let x = e.changedTouches[0].clientX;
            let y = e.changedTouches[0].clientY;
            //绘制
            ctx.lineTo(x, y);
            //描边
            ctx.stroke();
        });

        canvas.addEventListener('touchend', function(){

        });


    </script>
</body>
</html>